package cn.iscorpio.ssm.web;

import lombok.Data;

/**
 * @author chenkx
 * @date 2018-05-04.
 */
@Data
public class RestResponse<T> {
    private static final String SUCCESS = "SUCCESS";
    private int code;
    private String message;
    private T data;

    public static <T> RestResponse<T> success() {
        return new RestResponse();
    }

    public static <T> RestResponse<T> success(T data) {
        RestResponse<T> response = new RestResponse();
        response.setMessage("SUCCESS");
        response.setData(data);
        return response;
    }

    public static <T> RestResponse<T> error(RestCode code) {
        return new RestResponse(code);
    }

    public static <T> RestResponse<T> error(RestCode code, String message) {
        code.setMessage(message);
        return new RestResponse(code);
    }

    public RestResponse() {
        this(RestCode.OK);
    }

    public RestResponse(RestCode code) {
        this.code = code.code;
        this.message = code.msg;
    }

}
